added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / VBWebBrowserSuppressError / Readme.txt
blobaded2bab2c4405dff9107a8eabe7c9f3520b325f
1 ================================================================================
2        Windows APPLICATION: VBWebBrowserSuppressError Overview                        
3 ===============================================================================
4 /////////////////////////////////////////////////////////////////////////////
5 Summary:
6 The sample demonstrates how to make WebBrowser suppress errors. The errors include
8 1. Calling Script Just In Time Debugger.
10    function CallDebugger() {
11        debugger;
12    }
14    This could be disabled by the value of DisableJITDebugger in the key 
15    HKCU\Software\Microsoft\Internet Explorer\Main.
17    Notice that to disable JIT debugger, the application has to be restarted. 
19 2. Html element errors.
21    function CreateScriptError() {
22        throw ("Here is an error! ");
23    }
25    You can register the Document.Window.Error event and handle it.
26    
27    Notice that Document.Window.Error event will only take effect when JITDebugger
28    is disabled.
30 3. Navigation error. Like the page does not exist(Http 404 error).
32    DWebBrowserEvents2 Interface designates an event sink interface that an application
33    must implement to receive event notifications from the underlying ActiveX control,  
34    and there is a NavigateError Event in this interface. See
35    http://msdn.microsoft.com/en-us/library/aa768283(VS.85).aspx
36     
37 4. Other errors, like permission is needed when clipboard is used in Javascript. 
39    If you want to suppress all errors, you can set ScriptErrorsSuppressed to true. When 
40    ScriptErrorsSuppressed is set to true, the WebBrowser control hides all its dialog
41    boxes that originate from the underlying ActiveX control, not just script errors. 
42    Occasionally you might need to suppress script errors while displaying dialog boxes 
43    such as those used for browser security settings and user login. In this case, set 
44    ScriptErrorsSuppressed to false and suppress script errors in a handler for the 
45    HtmlWindow.Error event. 
47 ////////////////////////////////////////////////////////////////////////////////
48 Demo:
50 Disable JIT Debugger
52 Step1. Run VBWebBrowserSuppressError.exe.
54 Step2. Uncheck "Suppress JIT Debugger", and restart this application. 
55        You can skip this step if the checkbox is already unchecked.
57 Step3. Make the top textbox empty, and click the button "Go". This operation will let
58        WebBrowser navigate to a build-in html with errors.
60 Step4. Click "Launch Debugger" in the page, you will see a dialog to launch JIT debugger 
61        if VS is installed.
63 Step5. Check "Suppress JIT Debugger", and restart this application.
65 Step6. Make the top textbox empty, and click the button "Go".
67 Step7. Click "Launch Debugger" in the page, you will not see the  dialog to launch JIT 
68        debugger.
71 Suppress html element errors
73 Step1. Run VBWebBrowserSuppressError.exe.
75 Step2. Check "Suppress JIT Debugger", and restart this application.
76        You can skip this step if the checkbox is already checked.
78 Step3. Make the top textbox empty, and click the button "Go". This operation will let
79        WebBrowser navigate to a build-in html with errors.
81 Step4. Uncheck "Suppress Html Element Errors". 
83 Step5. Click "Script Error" in the page, you will see a WebPage error dialog.
85 Step6. Check "Suppress Html Element Errors". 
87 Step7. Click "Script Error" in the page, you will not see the WebPage error dialog.
88          
89          
91 Handle navigation error
93 Step1. Run VBWebBrowserSuppressError.exe.
95 Step2. Uncheck "Suppress Navigation Error". 
97 Step3. Type http://www.microsoft.com/NotExist.html the top textbox, and click the button "Go".
98        Microsoft.com will tell you that the page is not found.
100 Step4. Check "Suppress Navigation Error". 
102 Step5. Type http://www.microsoft.com/NotExist.html the top textbox, and click the button "Go".
103        You will see the build-in HTTP404 html.
107 Suppress all dialogs                
109 Step1. Run VBWebBrowserSuppressError.exe.
111 Step2. Make the top textbox empty, and click the button "Go". This operation will let
112        WebBrowser navigate to a build-in html with errors.
114 Step3. Uncheck "Suppress all dialog". 
116 Step4. Click "Security Dialog" in the page, you will see a "Windows Security Warning" dialog.
118 Step5. Make the top textbox empty, and click the button "Go" again. Or refresh this page in the 
119        Context menu.
121 Step6. Check "Suppress all dialog". 
123 Step7. Click "Security Dialog" in the page, you will not see the "Windows Security Warning"
124        dialog.
127 /////////////////////////////////////////////////////////////////////////////
128 Code Logic:
130 1. Create html file Error.htm. This web page can create script error, security warning and
131 launch JIT debugger.
133 2. Design a class WebBrowserEx that inherits class System.Windows.Forms.WebBrowser. This 
134    class supplies following features.
135    
136    2.1. Disable JIT Debugger.
137         The static property  DisableJITDebugger can get or set the value of "Disable Script
138             Debugger" in the key HKCU\Software\Microsoft\Internet Explorer\Main.
140    2.2. Suppress html element errors of document loaded in this browser.
141         Handle  the window error event of document loaded in this browser.
143    2.3. Handle navigation error.
144         The interface DWebBrowserEvents2 designates an event sink interface that an application
145                 must implement to receive event notifications from a WebBrowser control or from the 
146                 Windows Internet Explorer application. The event notifications include NavigateError 
147                 event that will be used in this application.
149    2.4 The class WebBrowser itself also has a Property ScriptErrorsSuppressed to hides all its 
150        dialog boxes that originate from the underlying ActiveX control, not just script errors.
151            
152 3. In the MainForm, handle the checkboxes CheckedChanged event to disable JIT debugger, suppress html 
153    element errors and suppress all dialog. 
154    
155    It also registers the NavigateError event of WebBrowserEx. If "Suppress Navigation Error" is
156    checked and the http status code is 404, then navigate to the build-in 404.htm.
159 /////////////////////////////////////////////////////////////////////////////
160 References:
161 http://msdn.microsoft.com/en-us/library/aa768283(VS.85).aspx
162 http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.scripterrorssuppressed.aspx
163 http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.createsink.aspx
164 /////////////////////////////////////////////////////////////////////////////